package com.xuwang.service.impl;

import com.xuwang.dto.SupervisoryInformationDto;
import com.xuwang.mapper.SupervisoryInformationMapper;
import com.xuwang.pojo.ComplaintsAccept;
import com.xuwang.pojo.SupervisoryInformation;
import com.xuwang.service.SupervisoryInformationService;
import com.xuwang.vo.SupervisoryInformationInsertVo;
import com.xuwang.vo.SupervisoryInformationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
  *督察信息表服务接口实现
  *@ClassName SupervisoryInformationServiceImpl
  *@Description TODO
  *@Author OuJunchen
  *@Date 2021/9/14 上午10:27
  *@Version 1.0
  */
@Service
public class SupervisoryInformationServiceImpl implements SupervisoryInformationService{

    @Resource
    private SupervisoryInformationMapper supervisoryInformationMapper;

    @Override
    public Map<String, Object> deleteByPrimaryKey (String id) {
        String[] idArray = id.split(",");
        List<String> list = new ArrayList<>();
        list.addAll(Arrays.asList(idArray));
        supervisoryInformationMapper.deleteByPrimaryKey(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "删除成功");
        return map;
    }

    @Override
    public int insert(SupervisoryInformation record) {
        return supervisoryInformationMapper.insert(record);
    }

    @Override
    public int insertOrUpdate(SupervisoryInformation record) {
        return supervisoryInformationMapper.insertOrUpdate(record);
    }

    @Override
    public Map<String, Object> insertOrUpdateSelective(SupervisoryInformationInsertVo supervisoryInformationInsertVo) {
        System.out.println(supervisoryInformationInsertVo);
        SupervisoryInformation supervisoryInformation = new SupervisoryInformation();
        BeanUtils.copyProperties(supervisoryInformationInsertVo, supervisoryInformation);
        System.out.println(supervisoryInformation);
        supervisoryInformationMapper.insertOrUpdateSelective(supervisoryInformation);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "新增成功");
        return map;
    }

    @Override
    public int insertSelective(SupervisoryInformation record) {
        return supervisoryInformationMapper.insertSelective(record);
    }

    @Override
    public SupervisoryInformation selectByPrimaryKey(Integer id) {
        return supervisoryInformationMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SupervisoryInformation record) {
        return supervisoryInformationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SupervisoryInformation record) {
        return supervisoryInformationMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateBatch(List<SupervisoryInformation> list) {
        return supervisoryInformationMapper.updateBatch(list);
    }

    @Override
    public int updateBatchSelective(List<SupervisoryInformation> list) {
        return supervisoryInformationMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert(List<SupervisoryInformation> list) {
        return supervisoryInformationMapper.batchInsert(list);
    }

    @Override
    public Map<String, Object> selectAll (int page, int limit, SupervisoryInformationVo supervisoryInformationVo) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", "查询失败!");
        page = (page - 1) * limit;
        List<SupervisoryInformationDto> list = supervisoryInformationMapper.selectAll(page, limit, supervisoryInformationVo);
        if (supervisoryInformationVo != null) {
            map.put("code", 0);
            map.put("msg", "查询成功!");
            map.put("pageCount", list.size());
            map.put("data", list);
        }
        return map;
    }
}
